﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;


namespace Projeto_Build_0.Models
{
    public class SampleData : DropCreateDatabaseAlways<JardimEntities>
    {
        protected override void Seed(JardimEntities context)
        {
           
            new List<Ementa>()
            {
               new Ementa { Sobremesa = "Pudim", Sopa="Caldo Verde" },
               new Ementa { Sobremesa = "Arroz Doce", Sopa="Creme de Cenoura" },
               new Ementa { Sobremesa= "Laranja", Sopa="Creme de Abobora" },
               new Ementa { Sobremesa= "Maça", Sopa="Feijão Verde"},
               new Ementa { Sobremesa= "Banana", Sopa="Canja" },

            }.ForEach(a => context.Ementas.Add(a));
            context.SaveChanges();


            new List<Roles>()
            {
               new Roles { Nome="EE" },
               new Roles { Nome="Funcionario" },
               new Roles { Nome="Administrador" },             

            }.ForEach(a => context.Roles.Add(a));
            context.SaveChanges();

            new List<Prato>()
            {
               new Prato { NomePrato="Peixe Cozido" },
               new Prato { NomePrato="Bacalhau á Brás" },
               new Prato { NomePrato="Lasanha" },
               new Prato { NomePrato="Hamburger com batata" },
               new Prato { NomePrato="Cozido á Portuguesa" },
               new Prato { NomePrato="Filetes com arroz" },
               new Prato { NomePrato="Carne á Bolonhesa" },
               new Prato { NomePrato="Peixe Assado com batatas" },

            }.ForEach(a => context.Pratos.Add(a));
            context.SaveChanges();

            new List<ListaPratos>()
            {
               new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 1) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 1) 
                select p).FirstOrDefault() },
              new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 2) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 1) 
                select p).FirstOrDefault() },
              new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 3) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 1) 
                select p).FirstOrDefault() },
              new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 4) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 1) 
                select p).FirstOrDefault() },

              new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 1) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 2) 
                select p).FirstOrDefault() },
              new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 4) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 2) 
                select p).FirstOrDefault() },
               new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 5) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 2) 
                select p).FirstOrDefault() },
              new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 6) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 2) 
                select p).FirstOrDefault() },

               new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 2) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 3) 
                select p).FirstOrDefault() },
              new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 6) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 3) 
                select p).FirstOrDefault() },
              new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 7) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 3) 
                select p).FirstOrDefault() },
               new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 8) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 3) 
                select p).FirstOrDefault() },

              new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 3) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 4) 
                select p).FirstOrDefault() },
               new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 4) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 4) 
                select p).FirstOrDefault() },
              new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 5) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 4) 
                select p).FirstOrDefault() },
               new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 6) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 4) 
                select p).FirstOrDefault() },

                new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 1) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 5) 
                select p).FirstOrDefault() },
               new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 2) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 5) 
                select p).FirstOrDefault() },
              new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 7) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 5) 
                select p).FirstOrDefault() },
               new ListaPratos { Prato=(from p in context.Pratos.ToList() 
                where (p.PratoId == 8) 
                select p).FirstOrDefault(), 
                Ementa=(from p in context.Ementas.ToList() 
                where (p.EmentaId == 5) 
                select p).FirstOrDefault() },

            }.ForEach(a => context.ListaPratos.Add(a));
            context.SaveChanges();  

            new List<DiaDaSemana>()
            {
               new DiaDaSemana { Dia= "Segunda" },
               new DiaDaSemana { Dia= "Terça" },
               new DiaDaSemana { Dia= "Quarta" },
               new DiaDaSemana { Dia= "Quinta" },
               new DiaDaSemana { Dia= "Sexta" },

            }.ForEach(a => context.DiaDaSemanas.Add(a));
            context.SaveChanges();

            new List<Sala>()
            {
               new Sala { NomeSala="Joaninhas", Observacoes="Alunos com 3 anos"},               

            }.ForEach(a => context.Salas.Add(a));
            context.SaveChanges();

            new List<SemanaEscolar>()
            {
               new SemanaEscolar { Ano=2011, NumeroSemana=1, 
                   Sala= (from p in context.Salas.ToList() 
                where (p.NomeSala == "Joaninhas") 
                select p).FirstOrDefault()},               

                new SemanaEscolar { Ano=2011, NumeroSemana=2, 
                   Sala= (from p in context.Salas.ToList() 
                where (p.NomeSala == "Joaninhas") 
                select p).FirstOrDefault()},

                new SemanaEscolar { Ano=2011, NumeroSemana=3, 
                   Sala= (from p in context.Salas.ToList() 
                where (p.NomeSala == "Joaninhas") 
                select p).FirstOrDefault()},

            }.ForEach(a => context.SemanaEscolars.Add(a));
            context.SaveChanges();

           

            new List<DiaEscolar>
            {
                new DiaEscolar {  Ementa = (from p in context.Ementas.ToList() 
                where (p.EmentaId == 1) 
                select p).FirstOrDefault(), DiaDaSemana = (from p in context.DiaDaSemanas.ToList() 
                where (p.Dia == "Segunda") 
                select p).FirstOrDefault(), 
                SemanaEscolar= (from p in context.SemanaEscolars.ToList() 
                where (p.NumeroSemana == 1 && p.Ano== 2011) 
                select p).FirstOrDefault()}, 
                new DiaEscolar { Ementa = (from p in context.Ementas.ToList() 
                where (p.EmentaId == 2) 
                select p).FirstOrDefault(),DiaDaSemana = (from p in context.DiaDaSemanas.ToList() 
                where (p.Dia == "Terça") 
                select p).FirstOrDefault(), 
                SemanaEscolar= (from p in context.SemanaEscolars.ToList() 
                where (p.NumeroSemana == 1 && p.Ano== 2011) 
                select p).FirstOrDefault()},
                new DiaEscolar { Ementa = (from p in context.Ementas.ToList() 
                where (p.EmentaId == 3) 
                select p).FirstOrDefault(),DiaDaSemana = (from p in context.DiaDaSemanas.ToList() 
                where (p.Dia == "Quarta") 
                select p).FirstOrDefault(), 
                SemanaEscolar= (from p in context.SemanaEscolars.ToList() 
                where (p.NumeroSemana == 1 && p.Ano== 2011) 
                select p).FirstOrDefault()},
                new DiaEscolar { Ementa = (from p in context.Ementas.ToList() 
                where (p.EmentaId == 4) 
                select p).FirstOrDefault(),DiaDaSemana = (from p in context.DiaDaSemanas.ToList() 
                where (p.Dia == "Quinta") 
                select p).FirstOrDefault(), 
                SemanaEscolar= (from p in context.SemanaEscolars.ToList() 
                where (p.NumeroSemana == 1 && p.Ano== 2011) 
                select p).FirstOrDefault()},
                new DiaEscolar { Ementa = (from p in context.Ementas.ToList() 
                where (p.EmentaId == 5) 
                select p).FirstOrDefault(),DiaDaSemana = (from p in context.DiaDaSemanas.ToList() 
                where (p.Dia == "Sexta") 
                select p).FirstOrDefault(), 
                SemanaEscolar= (from p in context.SemanaEscolars.ToList() 
                where (p.NumeroSemana == 1 && p.Ano== 2011) 
                select p).FirstOrDefault()},
                 new DiaEscolar { Ementa = (from p in context.Ementas.ToList() 
                where (p.EmentaId == 5) 
                select p).FirstOrDefault(),DiaDaSemana = (from p in context.DiaDaSemanas.ToList() 
                where (p.Dia == "Segunda") 
                select p).FirstOrDefault(), 
                SemanaEscolar= (from p in context.SemanaEscolars.ToList() 
                where (p.NumeroSemana == 2 && p.Ano== 2011) 
                select p).FirstOrDefault()},
            }.ForEach(a => context.DiaEscolars.Add(a));
            context.SaveChanges();

            new List<Evento>
            {
                new Evento { NomeEvento= "Evento1", Descricao= "Bue fixe", HoraFim=13 , HoraInicio=9, 
                    DiaEscolar= (from p in context.DiaEscolars.ToList() 
                where (p.DiaEscolarId == 1) 
                select p).FirstOrDefault()},
                new Evento { NomeEvento= "Evento2", Descricao= "Bue mau", HoraFim=13 , HoraInicio=8, 
                    DiaEscolar= (from p in context.DiaEscolars.ToList() 
                where (p.DiaEscolarId == 1) 
                select p).FirstOrDefault()},
                new Evento { NomeEvento= "Evento3", Descricao= "Bue mau", HoraFim=13 , HoraInicio=8, 
                    DiaEscolar= (from p in context.DiaEscolars.ToList() 
                where (p.DiaEscolarId == 6) 
                select p).FirstOrDefault()},
            }.ForEach(a => context.Eventos.Add(a));
            context.SaveChanges();
        }
        
    }
}